package signGrammar.util;

import java.util.HashMap;
import java.util.Map;

import signGrammar.CAddShapesExpression;
import signGrammar.CBlankShape;
import signGrammar.CExMultShapesExpression;
import signGrammar.CMinusShapesExpression;
import signGrammar.CNotShapeExpression;
import signGrammar.IShape;

public class UShapeExpression {
	private UShapeExpression() {}
	
	public static Map<String, IBinaryShapeExpression> getExpressions() {
		return expressionsMap;
	}
	public static Map<String, IUnaryShapeExpression> getUnaryExpressions() {
		return unaryExpressionsMap;
	}

	private static Map<String, IBinaryShapeExpression> expressionsMap;
	static{
		expressionsMap = new HashMap<String, IBinaryShapeExpression>();
		expressionsMap.put("+", new IBinaryShapeExpression(){
			@Override public IShape eval(IShape left, IShape right) {
				return new CAddShapesExpression(left,right);
			}});
		expressionsMap.put("-", new IBinaryShapeExpression(){
			@Override public IShape eval(IShape left, IShape right) {
				return new CMinusShapesExpression(left,right);
			}});
		expressionsMap.put("x", new IBinaryShapeExpression(){
			@Override public IShape eval(IShape left, IShape right) {
				return new CExMultShapesExpression(left,right);
			}});
	}
	public static IShape eval(IShape left, String binaryExpressionSign, IShape right){
		return expressionsMap.get(binaryExpressionSign).eval(left, right);
	}
	
	private static Map<String, IUnaryShapeExpression> unaryExpressionsMap;
	static{
		unaryExpressionsMap = new HashMap<String, IUnaryShapeExpression>();
		unaryExpressionsMap.put("~", new IUnaryShapeExpression(){
			@Override public IShape eval(IShape shape) {
				return new CNotShapeExpression( shape );
			}});
		unaryExpressionsMap.put("!", new IUnaryShapeExpression(){
			@Override public IShape eval(IShape shape) {
				return new CBlankShape( shape );
			}});
	}
	public static IShape eval(String sign,IShape shape){
		return unaryExpressionsMap.get( sign ).eval(shape);
	}
	
}
